package com.example.leetdemo.finash;

import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Solution672 {

    Set<String> str = new HashSet<>();
    public int flipLights(int n, int presses) {
        int[] light = new int[n];
        dps(light, 0, Math.min(presses, 3));
        return str.size();
    }

    private void dps(int[] light, int step, int presses) {
        if (step == presses) {
            str.add(parseString(light));
            return;
        }
        // 开关1
        for(int i = 0; i < light.length; i++) {
            light[i] = light[i] ^ 1;
        }
            dps(light, step + 1, presses);
        for (int i = 0; i < light.length; i++) {
            light[i] = light[i] ^ 1;
        }

        // 开关2
        for (int i = 1; i < light.length; i++) {
            light[i] = light[i] ^ 1;
            i++;
        }
        dps(light, step + 1, presses);
        for (int i = 1; i < light.length; i++) {
            light[i] = light[i] ^ 1;
            i++;
        }

        // 开关3
        for (int i = 0; i < light.length; i++) {
            light[i] = light[i] ^ 1;
            i++;
        }
        dps(light, step + 1, presses);
        for (int i = 0; i < light.length; i++) {
            light[i] = light[i] ^ 1;
            i++;
        }
        // 开关4
        for (int i = 0; 3 * i + 1 < light.length; i++) {
            light[i] = light[i] ^ 1;
            i++;
        }
        dps(light, step + 1, presses);
        for (int i = 0; 3 * i + 1 < light.length; i++) {
            light[i] = light[i] ^ 1;
            i++;
        }
    }

    private String parseString(int[] nums) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < nums.length; i++) {
            builder.append(nums[i]);
        }
        return builder.toString();
    }
}
